//
//  CYCategrayModel.m
//  cyydt
//
//  Created by chu on 2019/1/15.
//  Copyright © 2019 chu. All rights reserved.
//

#import "CYCategrayModel.h"

@implementation CYCategrayModel

+ (instancetype)modelWithDictionary:(NSDictionary *)dic{
    NSMutableDictionary *muDic = [NSMutableDictionary dictionaryWithDictionary:dic];
    [muDic setObject:[NSNumber numberWithBool:NO] forKey:@"isSelected"];
    if (muDic[@"child"] && [muDic[@"child"] isKindOfClass:[NSArray class]]) {
        NSMutableArray *child = [NSMutableArray arrayWithArray:muDic[@"child"]];

        NSMutableArray *childArr = [NSMutableArray arrayWithCapacity:0];
        for (NSDictionary *childDic in child) {
            NSMutableDictionary *childMuDic = [NSMutableDictionary dictionaryWithDictionary:childDic];
            if (childDic[@"name"]) {
                [childMuDic setObject:childDic[@"name"] forKey:@"catname"];
                [childMuDic setObject:childDic[@"id"] forKey:@"catid"];
                [childMuDic setObject:childDic[@"childCates"] forKey:@"child"];
                [childMuDic removeObjectForKey:@"id"];
                [childMuDic removeObjectForKey:@"name"];
                [childMuDic removeObjectForKey:@"childCates"];
            }
            
            [childMuDic setObject:[NSNumber numberWithBool:NO] forKey:@"isSelected"];
            CYCategrayModel *model = [CYCategrayModel modelWithDictionary:childMuDic];
            [childArr addObject:model];
        }
        [muDic setObject:childArr forKey:@"child"];
    }
    return [[self alloc] initWithDictionary:muDic];
}

//- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
//    [super setValue:value forUndefinedKey:key];
//    if ([key isEqualToString:@"id"]) {
//        self.ID = value;
//    }
//}

//- (void)setValue:(id)value forKey:(NSString *)key{
//    [super setValue:value forKey:key];
//    if ([key isEqualToString:@"name"]) {
//        self.catname = value;
//    }
//    if ([key isEqualToString:@"id"]) {
//        self.catid = value;
//    }
//    if ([key isEqualToString:@"childCates"]) {
//        self.child = value;
//    }
//}

@end
